<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>元信息</title>
  <script src="./js/jexcel.js"></script>
  <script src="./js/jsuites.js"></script>
  <link rel="stylesheet" href="./css/jsuites.css" type="text/css" />
  <link rel="stylesheet" href="./css/jexcel.css" type="text/css" />
</head>

<body>
  <h1>元信息</h1>

  <h3>此功能可以帮助您对用户隐藏有关单元格的导入信息。</h3>
  <p>您可以在初始化过程中定义任何元信息，或者在getMeta或setMeta方法之后以编程方式定义。</p>
  <div id="spreadsheet"></div>

  <div>
    <button type="button" id="btn1">为多个列设置元信息</button>
    <button type="button" id="btn2">为B2设置元信息</button>
    <button type="button" id="btn3">获取A1元信息</button>
    <button type="button" id="btn4">获取所有元信息</button>
  </div>


  <div style="margin-top: 30px;">
    <textarea id="console" style="width: 100%;"></textarea>
  </div>
</body>

<script type="module">
  import { text } from "./js/language.js";

  let oBtn1 = document.getElementById('btn1');
  let oBtn2 = document.getElementById('btn2');
  let oBtn3 = document.getElementById('btn3');
  let oBtn4 = document.getElementById('btn4');

  var data = [
    ['US', 'Apples', 'Yes', '2019-02-12'],
    ['CA;US;UK', 'Carrots', 'Yes', '2019-03-01'],
    ['CA;BR', 'Oranges', 'No', '2018-11-10'],
    ['BR', 'Coconuts', 'Yes', '2019-01-12'],
  ];

  var table = jspreadsheet(document.getElementById('spreadsheet'), {
    data: data,
    columns: [
      { type: 'dropdown', title: 'Product Origin', width: '300px', url: './static/countries.json', autocomplete: true, multiple: true },
      { type: 'text', title: 'Description', width: '200px' },
      { type: 'dropdown', title: 'Stock', width: '100px', source: ['No', 'Yes'] },
      { type: 'calendar', title: 'Best before', width: '100px' },
    ],
    meta: {
      A1: { myMeta: 'this is just a test', otherMetaInformation: 'other test' },
      A2: { info: 'test' }
    },
    text
  });

  oBtn1.onclick = function () {
    table.setMeta({ C1: { id: '1', y: '2019' }, C2: { id: '2' } });
  }

  oBtn2.onclick = function () {
    table.setMeta('B2', 'myMetaData', prompt('myMetaData:'));
  }

  oBtn3.onclick = function () {
    document.getElementById('console').value = JSON.stringify(table.getMeta('A1'));
  }
  oBtn4.onclick = function () {
    document.getElementById('console').value = JSON.stringify(table.getMeta());
  }
</script>

</html>